package com.wuyou.controller;

import com.wuyou.domain.Result;
import com.wuyou.entity.TbFurniture;
import com.wuyou.entity.TbWarranty;
import com.wuyou.mapper.TbFurnitureMapper;
import com.wuyou.service.ITbFurnitureService;
import com.wuyou.service.ITbWarrantyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yz
 * @since 2022-10-06
 */
@RestController
@RequestMapping("warranty")
@Api(value = "保修接口文档")
public class TbWarrantyController {

    @Autowired
    private ITbFurnitureService functionalService;

    @Autowired
    private ITbWarrantyService warrantyService;


    //获取需要保修物品的ID
    @PostMapping("selectById")
    @ApiOperation("根据id查询物品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "furnitureName", value = "物品ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "TbFurniture", value = "保修实体类",required = false, dataTypeClass = TbFurniture.class,paramType ="body" )
    })
    public Result selectById(String furnitureName, TbFurniture TbFurniture) {
        try {
            TbFurniture furniture = functionalService.selectByName(furnitureName);
            //增加到保修表里
            Integer furnitureId1 = furniture.getFurnitureId();
            TbWarranty warranty = new  TbWarranty();
            warranty.setFurnitureId(Long.valueOf(furnitureId1));
            warrantyService.save(warranty);
            return Result.OK();
        }catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR();
        }
    }


}